home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / psgui130.zip / PGUIMSE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-01  |  9KB  |  396 lines

  1. {
  2.  
  3.                                                       ╔══════════════════╗
  4.                                                       ║  PGUI Graphic    ║
  5.                                                       ║  Mouse Unit Std  ║
  6.                                                       ║    Rev.  1.00    ║
  7.                                                       ╚══════════════════╝
  8.  
  9. }
  10.  
  11. {$F+} {$O-} {$A+} {$G-}
  12. {$V-} {$B-} {$X-} {$N+} {$E+}
  13.  
  14. {$I FINAL.PAS}
  15.  
  16. {$IFDEF FINAL}
  17.   {$I-} {$R-}
  18.   {$D-} {$L-} {$S-}
  19. {$ENDIF}
  20.  
  21. Unit PGUIMSE;
  22.  
  23. Interface
  24.  
  25. Uses CRT,Dos,PGUIMDef;
  26.  
  27. Procedure Init         (Installed:Boolean);
  28. Procedure Show;
  29. Procedure Hide;
  30. Procedure SetSpeed     (Mousems:Byte);
  31. Procedure SetShape     (Shape:Pointer);
  32. Procedure SetXY        (X,Y:Word);
  33. Procedure SetBounds    (X1,Y1,X2,Y2:Word);
  34. Procedure GetPresses   (Var X,Y:Word;Var Button:Byte;Var Held:Boolean;
  35.                         Var NumTimes:Word);
  36. Procedure GetXY        (Var X,Y:Word);
  37. Procedure GetStatus    (Var X,Y:Word;Var Left,Right,Middle:Boolean);
  38. Procedure GetClick     (Var X1, Y1, X2, Y2:Word; Var MouseButton:Byte;
  39.                         Var Held,Doubled:Boolean);
  40.  
  41.  
  42. Implementation
  43.  
  44. Procedure Init(Installed:Boolean);
  45. Begin
  46.   If Not Installed Then
  47.     Installed:=False
  48.   Else
  49.   Asm
  50.     xor   ax, ax
  51.     int   33h
  52.     and   ax, 1         {ax = $FFFF if installed, Else 0}
  53.     mov   Installed, al
  54.   End;
  55.   Active:=Installed;
  56.   If Installed Then SetSpeed(25);
  57. End;
  58.  
  59. Procedure Show; Assembler;
  60.  
  61. { ╔════════════════════════════════════════════════════════════════════════╗ }
  62. { ║  Show mouse on screen.                                                 ║ }
  63. { ╚════════════════════════════════════════════════════════════════════════╝ }
  64.  
  65. Asm
  66.   mov ax, 1
  67.   int 33h
  68. End;
  69.  
  70. Procedure Hide; Assembler;
  71.  
  72. { ╔════════════════════════════════════════════════════════════════════════╗ }
  73. { ║  Mouse still active but hidden, not on screen.                         ║ }
  74. { ╚════════════════════════════════════════════════════════════════════════╝ }
  75.  
  76. Asm
  77.   mov ax, 2
  78.   int 33h
  79. End;
  80.  
  81. Procedure SetSpeed(Mousems:Byte);
  82.  
  83. { ╔════════════════════════════════════════════════════════════════════════╗ }
  84. { ║  Sets up the ComputerSpeed variable for mouse double click speed.      ║ }
  85. { ╚════════════════════════════════════════════════════════════════════════╝ }
  86.  
  87. Var
  88.    MBC       :0..2;
  89.    H,M,S,S100:Word;
  90.    LoopAmount,
  91.    Counter,
  92.    Total100b,
  93.    Total100  :LongInt;
  94.    Regs      :Registers;
  95.    C         :Char;
  96.    Fraction  :Real;
  97.  
  98. Begin
  99.   If Not Active Then
  100.   Begin
  101.     ComputerSpeed:=1000;
  102.     Exit;
  103.   End;
  104.  
  105.   LoopAmount:=9000;
  106.   Repeat
  107.     Inc(LoopAmount,1000);
  108.     GetTime(H,M,S,S100);
  109.     Total100:=S100;
  110.     Inc(Total100,S*100);
  111.     Inc(Total100,M*60*100);
  112.     Inc(Total100,H*60*60*100);
  113.     MBC:=0;
  114.     For Counter:=1 to LoopAmount do
  115.     Begin                                   {Waste Time Approx time for Mouse Check}
  116.       Regs.AX:=5;
  117.       Regs.BX:=MBC;
  118.       Intr($33,Regs);
  119.       If MBC=2 Then MBC:=0 Else Inc(MBC);
  120.       If (Regs.BX<>0) Then ;                {The Until Equivalent}
  121.       If KeyPressed Then C:=ReadKey;
  122.     End;
  123.     GetTime(H,M,S,S100);
  124.     Total100b:=S100;
  125.     Inc(Total100b,S*100);
  126.     Inc(Total100b,M*60*100);
  127.     Inc(Total100b,H*60*60*100);
  128.  
  129.     If LoopAmount>2100000000 Then
  130.     Begin
  131.       WriteLn('Unable to set Mouse Double Click Timer.');
  132.       Halt(0);
  133.     End;
  134.   Until (Total100b>Total100+10);
  135.  
  136.   Total100:=Total100b-Total100;   {Time Taken to do loop}
  137.   Fraction:=Mousems/Total100;     {We want time to be Mousems ms}
  138.   ComputerSpeed:=Round(Fraction*LoopAmount);
  139. End;
  140.  
  141. Procedure SetShape(Shape:Pointer);
  142.  
  143. Var
  144.   Segm, Ofst:Word;
  145.  
  146. Begin
  147.   Segm:=Seg(Shape^);
  148.   Ofst:=Ofs(Shape^);
  149.   Asm
  150.     mov   ax, 9
  151.     mov   es, Segm
  152.     mov   bx, Ofst
  153.     mov   dx, es:[bx+64]        {X Hot Spot}
  154.     mov   cx, es:[bx+66]        {Y Hot Spot}
  155.     xchg  bx, dx
  156.     int   33h
  157.   End;
  158. End;
  159.  
  160. Procedure SetXY(X,Y:Word); Assembler;
  161.  
  162. { ╔════════════════════════════════════════════════════════════════════════╗ }
  163. { ║  Mouse the mouse to a VGA co-ordinate on the screen.                   ║ }
  164. { ╚════════════════════════════════════════════════════════════════════════╝ }
  165.  
  166. Asm
  167.   mov  ax,4
  168.   mov  cx,X
  169.   mov  dx,Y
  170.   int  33h
  171. End;
  172.  
  173. Procedure SetBounds(X1,Y1,X2,Y2:Word); Assembler;
  174.  
  175. { ╔════════════════════════════════════════════════════════════════════════╗ }
  176. { ║  Lock the mouse in a rectangle of the screen.                          ║ }
  177. { ╚════════════════════════════════════════════════════════════════════════╝ }
  178.  
  179. Asm
  180.   mov  ax,7
  181.   mov  cx,X1
  182.   mov  dx,X2
  183.   int  33h
  184.   mov  ax,8
  185.   mov  cx,Y1
  186.   mov  dx,Y2
  187.   int  33h
  188. End;
  189.  
  190. Procedure GetPresses(Var X,Y:Word;Var Button:Byte;Var Held:Boolean;Var NumTimes:Word); Assembler;
  191.  
  192. { ╔════════════════════════════════════════════════════════════════════════╗ }
  193. { ║                                                                        ║ }
  194. { ║ Returns the Co-Ordinate of Last Button Press For Buttons.              ║ }
  195. { ║ Returns which button was pressed (0..2) or 255 if no button has been   ║ }
  196. { ║ pressed.                                                               ║ }
  197. { ║ Returns Held True if the button is still being held down.              ║ }
  198. { ║                                                                        ║ }
  199. { ╚════════════════════════════════════════════════════════════════════════╝ }
  200.  
  201. Label EndOfCheck,NotHeld,NoButtons,EndOfSub,
  202.       Button0,Button1,Button2,VeryEndOfSub;
  203.  
  204. Asm
  205.   mov  ax,5
  206.   mov  bx,0
  207.   mov  si,1
  208.   int  33h
  209.   cmp  bx,0             {Test Button 0}
  210.   jne  EndOfCheck
  211.  
  212.   mov  ax,5
  213.   mov  bx,1
  214.   mov  si,2
  215.   int  33h
  216.   cmp  bx,0             {Test Button 1}
  217.   jne  EndOfCheck
  218.  
  219.   mov  ax,5
  220.   mov  bx,2
  221.   mov  si,4
  222.   int  33h
  223.   cmp  bx,0             {Test Button 2}
  224.   jne  EndOfCheck
  225.  
  226.   jmp  NoButtons
  227.  
  228. EndOfCheck:
  229.  
  230.   les  di,NumTimes
  231.   mov  es:[di],bx
  232.   les  di,X
  233.   mov  es:[di],cx
  234.   les  di,Y
  235.   mov  es:[di],dx
  236.  
  237.   les  di,Held
  238.   and  ax,si
  239.   cmp  ax,0
  240.   je   NotHeld
  241.  
  242.   mov  al,1
  243.   jmp  EndOfSub
  244.  
  245. NotHeld:
  246.  
  247.   mov  al,0
  248.   jmp  EndOfSub
  249.  
  250. NoButtons:
  251.  
  252.   mov  si,0
  253.   mov  ax,0
  254.   les  di,NumTimes
  255.   mov  es:[di],ax
  256.   les  di,X
  257.   mov  es:[di],ax
  258.   les  di,Y
  259.   mov  es:[di],ax
  260.   les  di,Held
  261.   mov  al,0
  262.  
  263. EndOfSub:
  264.  
  265.   mov  es:[di],al       {Move value into Held}
  266.  
  267.   les  di,Button
  268.   cmp  si,1
  269.   je   Button0
  270.   cmp  si,2
  271.   je   Button1
  272.   cmp  si,4
  273.   je   Button2
  274.  
  275.   mov  al,0ffh            {No Button}
  276.  
  277.   jmp  VeryEndOfSub
  278.  
  279. Button0:
  280.  
  281.   mov  al,0
  282.   jmp  VeryEndOfSub
  283.  
  284. Button1:
  285.  
  286.   mov  al,1
  287.   jmp  VeryEndOfSub
  288.  
  289. Button2:
  290.  
  291.   mov  al,2
  292.  
  293. VeryEndOfSub:
  294.  
  295.   mov  es:[di],al               {Move a value into Button}
  296.  
  297. End;
  298.  
  299. Procedure GetXY(Var X,Y:Word); Assembler;
  300. Asm
  301.   mov  ax,3
  302.   int  33h
  303.   les  di,X
  304.   mov  es:[di],cx
  305.   les  di,Y
  306.   mov  es:[di],dx
  307. End;
  308.  
  309. Procedure GetStatus(Var X,Y:Word;Var Left,Right,Middle:Boolean); Assembler;
  310. Asm
  311.   mov  ax,3
  312.   int  33h
  313.   les  di,X
  314.   mov  es:[di],cx
  315.   les  di,Y
  316.   mov  es:[di],dx
  317.  
  318.   mov  ax,bx
  319.   and  ax,1
  320.   les  di,Left
  321.   mov  es:[di],al
  322.  
  323.   mov  ax,bx
  324.   and  ax,2
  325.   shr  ax,1
  326.   les  di,Right
  327.   mov  es:[di],al
  328.  
  329.   mov  ax,bx
  330.   and  ax,4
  331.   shr  ax,1
  332.   shr  ax,1
  333.   les  di,Middle
  334.   mov  es:[di],al
  335. End;
  336.  
  337. Procedure GetClick(Var X1, Y1, X2, Y2:Word;
  338.                    Var MouseButton:Byte;
  339.                    Var Held,Doubled:Boolean);
  340.  
  341. { ╔════════════════════════════════════════════════════════════════════════╗ }
  342. { ║  Return the VGA co-ordinate of the mouse once a key or mouse button    ║ }
  343. { ║  has been pressed.  Double set True for a Double Click.                ║ }
  344. { ║  Also returns which button is being pressed or held.                   ║ }
  345. { ╚════════════════════════════════════════════════════════════════════════╝ }
  346.  
  347. Var
  348.   Button2    :Byte;
  349.   NumPresses :Word;
  350.   X          :LongInt;
  351.   HeldA,
  352.   HeldB,
  353.   HeldC      :Boolean;
  354.  
  355. Begin
  356.   Doubled:=False;
  357.   Held:=False;
  358.  
  359.   If Active Then
  360.   Begin
  361.     Repeat
  362.       GetPresses(X1,Y1,MouseButton,Held